<template>
  <div class="box">
    <!-- <div class="feedback_title"></div> -->
    <van-cell-group>
      <van-field
        v-model="text"
        rows="8"
        label="意见反馈"
        type="textarea"
        placeholder="请描述您遇到的问题或建议，我们会尽快改进"
        show-word-limit
      />
    </van-cell-group>
    <van-cell-group>
      <van-field
        :style="{marginTop:'10px'}"
        v-model="tel"
        required
        number
        label="联系电话"
        type="tel"
        placeholder="请输入正确的联系方式"
        show-word-limit
      />
    </van-cell-group>
    <van-button
      round
      :style="{width:'95%',height:'5.5vh',lineHeight:'5.5vh',position:'fixed',bottom:'10vh',left:'2vw'}"
      color="#3C9BFB"
      v-show="isOriginHei"
      @click="showSubmit"
    >提交</van-button>
  </div>
  <!-- :style="{borderBottom:'1px solid #c0c0c09e',background:'#fafafa'}" -->
</template>
    
<script type="text/javascript">
import { Field, Cell, CellGroup, Button } from "vant";
export default {
  data() {
    return {
      text: "",
      tel: "",
      isOriginHei: true,
      documentHeight: document.documentElement.clientHeight
    };
  },
  components: {
    [Field.name]: Field,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Button.name]: Button
  },
   created(){
     dd.biz.navigation.setTitle({
        title: "意见反馈" //控制标题文本，空字符串表示显示默认文本
      });
  },
  methods: {
    /**
     * rfj
     * 提交事件
     */
    async showSubmit() {
        let corpId = localStorage.getItem("custid");
      // let corpId = this.$utils.getUrlKey("custid");
      let userId= localStorage.getItem("userId");
      if (this.tel == "") {
        this.$toast("手机号不能为空！");
      } else {
        let re = /^1\d{10}$/;
        let b = /\d/;
        if (b.test(this.text)) {
           this.$toast("意见反馈只能是汉字、字母");
        } else {
          if (re.test(this.tel)) {
            const res = await this.$http.get(`yuepoints/feedback`, {
              params: {
                corpId: corpId,
                userId: userId,
                phone: this.tel,
                content: this.text
              }
            });
            const {
              data: { errcode }
            } = res;
            if (errcode == "0000") {
              this.$toast("提交成功");
            }
          } else {
            this.$toast("手机号格式错误！");
          }
        }
      }
    }
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        if (this.documentHeight > document.documentElement.clientHeight) {
          this.isOriginHei = false;
        } else {
          this.isOriginHei = true;
        }
      })();
    };
  }
};
</script>

<style lang="less" scoped>
/deep/ .van-field__label {
  font-weight: 700;
}
</style>
